package com.rongshu.view.penpal.adapter;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;

import com.rongshu.utils.Constant;
import com.rongshu.view.base.BaseFragment;
import com.rongshu.view.penpal.fragment.Penpal_PostListFragment;

/**
 * created by zhengweis on 2018/11/1.
 * description：
 */
public class PenpalArticleTypePageAdapter extends FragmentStatePagerAdapter {
    String[] titles = {"帖子", "文章"};
    private int penpalwill_id;

    public PenpalArticleTypePageAdapter(FragmentManager fm, int penpalwill_id) {
        super(fm);
        this.penpalwill_id = penpalwill_id;
    }

    @Override
    public Fragment getItem(int position) {
        return createForNoExpand(position);
    }

    @Override
    public int getCount() {
        return titles.length;
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return titles[position];
    }

    private Fragment createForNoExpand(int position) {
        BaseFragment fragment = null;
        Bundle bundle = new Bundle();
        bundle.putInt("penpalwill_id", penpalwill_id);
        switch (position) {
            case 0:
                bundle.putInt("type", Constant.POST);
                fragment = new Penpal_PostListFragment();
                break;
            case 1:
                bundle.putInt("type", Constant.ARTICLE);
                fragment = new Penpal_PostListFragment();
                break;
        }
        fragment.setArguments(bundle);
        return fragment;
    }
}